package com.sskj.api.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sskj.api.domain.ThingModelTemplate;
import com.sskj.api.service.IThingModelTemplateService;
import com.sskj.api.vo.req.ThingModelTemplateReq;
import com.sskj.common.util.ApiResponseUtil;
import com.sskj.common.vo.ApiResponse;
import com.sskj.common.vo.SimplePagination;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "物模型库模块")
@RestController
@RequestMapping("/admin/thingModelTemplate")
@Validated
public class ThingModelTemplateController {

    @Autowired
    private IThingModelTemplateService thingModelTemplateService;

    @Operation(summary = "新增")
    @PostMapping("add")
    public ApiResponse<Object> add(@Valid @RequestBody ThingModelTemplate modelTemplate) {
        thingModelTemplateService.add(modelTemplate);

        return ApiResponseUtil.success();
    }

    @Operation(summary = "更新")
    @PostMapping("update")
    public ApiResponse<Object> update(@Valid @RequestBody ThingModelTemplate modelTemplate) {
        thingModelTemplateService.update(modelTemplate);

        return ApiResponseUtil.success();
    }

    @Operation(summary = "分页查询")
    @GetMapping("pageList")
    public ApiResponse<SimplePagination<ThingModelTemplate>> pageList(ThingModelTemplateReq req) {
        IPage<ThingModelTemplate> thingModelTemplateIPage = thingModelTemplateService.pageList(req);

        return ApiResponseUtil.success(thingModelTemplateIPage);
    }
}
